package com.zhoujinlong.ui.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.android.core.adapter.RecyclerAdapter;
import com.android.core.adapter.RecyclerViewHolder;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.zhoujinlong.R;
import com.zhoujinlong.model.bean.ExerciseBean;
import com.zhoujinlong.utils.BaseUtil;

import java.util.List;

/**
 * @author: 蜡笔小新
 * @date: 2016-05-31 14:15
 * @GitHub: https://github.com/meikoz
 */
public class ExerciseRecyclerAdapter extends RecyclerAdapter<ExerciseBean> {

    private Context mContext;

    public ExerciseRecyclerAdapter(Context context, int layoutId, List<ExerciseBean> datas) {
        super(context, layoutId, datas);
        this.mContext = context;
    }

    @Override
    public void convert(final RecyclerViewHolder holder, final ExerciseBean item) {
        ImageView imageView = (ImageView) holder.getView(R.id.iv_trainer_guide);
        Log.i("--->","--------"+BaseUtil.getDrawableId(mContext, item.getPicture()));
        Drawable drawable = mContext.getResources().getDrawable(BaseUtil.getDrawableId(mContext, item.getPicture()));
//        Drawable drawable = mContext.getResources().getDrawable(R.drawable.waist_01);
        int height = (int) (BaseUtil.dp2px(mContext, 40));
        int width = (int) ((float) drawable.getIntrinsicWidth() / (float) drawable
                .getIntrinsicHeight()* height);
        if (width == 0) {
            width = drawable.getIntrinsicWidth();
        }
        imageView.setLayoutParams(new LinearLayout.LayoutParams(width, height));
        Glide.with(mContext).load(BaseUtil.getDrawableId(mContext, item.getPicture())).diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);
        holder.setText(R.id.tv_trainer_title, item.getTitle());
    }
}
